class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int prevMin = INT_MAX;
        int ret = 0;
        for (auto x : prices)
        {
            if (x < prevMin)
            {
                prevMin = x;
            }
            else
            {
                int tmp = x - prevMin;
                ret = max(ret, tmp);
            }
        }

        return ret;
    }
};